<template>
  <div class='detail-wrap'>
    <el-dialog v-model="dialogVisible" :title="title" width="600px" class="one-dialog" draggable @close="emit('close')">
      <el-form ref="ruleFormRef" :model="ruleForm" :rules='rules' label-width="100px">
        <el-form-item label="提供方编码" prop='code'>
          <el-input v-model="ruleForm.code" />
        </el-form-item>
        <el-form-item label="提供方" prop='name'>
          <el-input v-model="ruleForm.name" />
        </el-form-item>
      </el-form>
      <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="handleSubmit()" :loading="isLoading">确定</el-button>
      </span>
      </template>
    </el-dialog>
  </div>
</template>
<script lang='ts' setup>
import to from 'await-to-js'
import type { FormInstance } from 'element-plus'

const emit = defineEmits(['close'])
const props = defineProps<{
  currentRow: any
  type: string
}>()
const title = ref('修改类目')
const dialogVisible = ref<boolean>(true)
const ruleFormRef = ref<FormInstance>()
const isLoading = ref(false)
const data = reactive({
  ruleForm: {
    code: '',
    name: ''
  },
  rules: {
    code: [{ required: true, message: '请填写' }],
    name: [{ required: true, message: '请填写' }],
  }
})
const { ruleForm, rules } = toRefs<any>(data)

const handleSubmit = async () => {
  const validate = await to(ruleFormRef.value.validate())
  if (!validate[1]) return
  const data = JSON.parse(JSON.stringify(ruleForm.value))
  isLoading.value = true
  // const [err] = await to(props.type === 'add' ? addUser(data) : editUser(data))
  // isLoading.value = false
  // if (err) return
  ElMessage.success('操作成功')
  emit('close', true)
}
</script>
<style lang='scss' scoped>
.detail-wrap{

}
</style>